package com.lanchetech.user.controller;

import com.lanchetech.bean.request.*;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import com.lanchetech.service.CommonAfterSaleService;
import com.lanchetech.user.service.MerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "商户接口", tags = "商户接口")
@RequestMapping("/api/merchant")
@RestController
public class MerchantController {

    @Autowired
    MerchantService merchantService;

    @Autowired
    CommonAfterSaleService afterSaleService;

    @ApiOperation("获取售后分页")
    @PostMapping("/getAfterSalePage")
    public ResultData<BasePageResp<AfterSaleResp>> getAfterSalePage(@RequestBody AfterSalePageReq req) {
        return merchantService.getAfterSalePage(req);
    }

    @ApiOperation("同意换货并编辑换货快递物流信息")
    @PostMapping("/editAfterSaleLogistics")
    public BaseResp editAfterSaleLogistics(@RequestBody AfterSale req) {
        return merchantService.editAfterSaleLogistics(req);
    }

    @ApiOperation("拒绝售后申请")
    @PostMapping("/rejectAfterSale")
    public BaseResp rejectAfterSale(@RequestBody AfterSale req) {
        return merchantService.rejectAfterSale(req);
    }

    @ApiOperation("同意售后，等待退货")
    @PostMapping("/confirmAfterSale")
    public BaseResp confirmAfterSale(@RequestBody AfterSale req) {
        return merchantService.confirmAfterSale(req);
    }

    @ApiOperation("同意退款")
    @PostMapping("/agreeRefund")
    public BaseResp agreeRefund(@RequestBody AfterSale req) {
        return afterSaleService.commonAgreeRefund(req);
    }

    @ApiOperation("订单发货填写快递物流信息")
    @PostMapping("/editOrderLogistics")
    public BaseResp editOrderLogistics(@RequestBody Orders orders) {
        return merchantService.editOrderLogistics(orders);
    }

    @ApiOperation("获取售后详情")
    @GetMapping("/getAfterSaleDetail")
    public ResultData<AfterSaleDetailResp> getAfterSaleDetail(@RequestParam("id") Long id) {
        return merchantService.getAfterSaleDetail(id);
    }

    @ApiOperation("获取商家提现分页")
    @PostMapping("/getTenantWithdrawPage")
    public ResultData<BasePageResp<TenantWithdraw>> getTenantWithdrawPage(@RequestBody PageReq req) {
        return merchantService.getTenantWithdrawPage(req);
    }

    @ApiOperation("发起商家提现申请")
    @PostMapping("/createTenantWithdraw")
    public BaseResp createTenantWithdraw(@RequestBody TenantWithdraw req) {
        return merchantService.createTenantWithdraw(req);
    }

    @ApiOperation("获取商家资金信息")
    @GetMapping("/getTenantFundInfo")
    public ResultData<TenantFundVO> getTenantFundInfo() {
        return merchantService.getTenantFundInfo();
    }

    @ApiOperation("获取商家余额流水")
    @PostMapping("/getBalanceFlowPage")
    public ResultData<BasePageResp<TenantFlow>> getBalanceFlowPage(@RequestBody PageReq req) {
        return merchantService.getBalanceFlowPage(req);
    }

    @ApiOperation("获取当前用户是否拥有商家钱包的查看权限")
    @GetMapping("/getMerchantAuth")
    public ResultData<String> getMerchantAuth(@AuthenticationPrincipal User user) {
        return merchantService.getMerchantAuth(user);
    }

    @ApiOperation("获取首页统计")
    @PostMapping("/getHomeStatistics")
    public ResultData<MerchantHomeStatisticsVO> getHomeStatistics(@RequestBody HomeStatisticsReq req) {
        return merchantService.getHomeStatistics(req);
    }

    @ApiOperation("修改店铺logo")
    @PostMapping("/editShopAvatar")
    public BaseResp editShopAvatar(@RequestBody Shop req) {
        return merchantService.editShopAvatar(req);
    }

    @ApiOperation("修改店铺名称")
    @PostMapping("/editShopNickname")
    public BaseResp editShopNickname(@RequestBody Shop req) {
        return merchantService.editShopNickname(req);
    }

    @ApiOperation("修改店铺售后电话")
    @PostMapping("/editShopAfterSalePhone")
    public BaseResp editShopAfterSalePhone(@RequestBody Shop req) {
        return merchantService.editShopAfterSalePhone(req);
    }

    @ApiOperation("修改店铺售后地址")
    @PostMapping("/editShopAfterSaleAddress")
    public BaseResp editShopAfterSaleAddress(@RequestBody Shop req) {
        return merchantService.editShopAfterSaleAddress(req);
    }

    @ApiOperation("修改店铺退货地址")
    @PostMapping("/editShopReturnAddress")
    public BaseResp editShopReturnAddress(@RequestBody Shop req) {
        return merchantService.editShopReturnAddress(req);
    }

    @ApiOperation("添加或编辑商品")
    @PostMapping("/editSpuAndSku")
    public BaseResp editSpuAndSku(@RequestBody SpuEditVO spuEditVO) {
        return merchantService.editSpuAndSku(spuEditVO);
    }

    @ApiOperation("获取运费模板列表")
    @GetMapping("/getFreightList")
    public ResultData<List<Freight>> getFreightList() {
        return merchantService.getFreightList();
    }

    @ApiOperation("获取所有类目列表")
    @GetMapping("/getAllCategoryList")
    public ResultData<List<Category>> getAllCategoryList(@RequestParam("type") Byte type) {
        return merchantService.getAllCategoryList(type);
    }

    @ApiOperation("获取子类目列表")
    @GetMapping("/getChildrenCategory")
    public ResultData<List<Category>> getChildrenCategory(@RequestParam("id") Long id) {
        return merchantService.getChildrenCategory(id);
    }

    @ApiOperation("获取根类目列表")
    @GetMapping("/getRootCategoryList")
    public ResultData<List<Category>> getRootCategoryList(@RequestParam("type") Byte type) {
        return merchantService.getRootCategoryList(type);
    }

    @ApiOperation("获取单位列表")
    @GetMapping("/getUnitList")
    public ResultData<List<Unit>> getUnitList() {
        return merchantService.getUnitList();
    }

    @ApiOperation("获取商品SPU分页")
    @PostMapping("/getSpuPage")
    public ResultData<BasePageResp<SpuResp>> getSpuPage(@RequestBody SpuReq req) {
        return merchantService.getSpuPage(req);
    }

    @ApiOperation("获取商品")
    @GetMapping("/getSpuEditDetail")
    public ResultData<SpuEditVO> getSpuEditDetail(@RequestParam("id") Long id) {
        return merchantService.getSpuEditDetail(id);
    }

    @ApiOperation("删除商品")
    @GetMapping("/deleteProduct")
    public BaseResp deleteProduct(@RequestParam("id") Long id) {
        return merchantService.deleteProduct(id);
    }


    @ApiOperation("修改库存")
    @PostMapping("/editSkuStock")
    public BaseResp editSkuStock(@RequestBody EditSkuStockReq req) {
        return merchantService.editSkuStock(req);
    }

    @ApiOperation("修改单个SKU库存")
    @GetMapping("/editSingleSkuStock")
    public BaseResp editSingleSkuStock(@RequestParam("skuId") Long skuId, @RequestParam("stock") Integer stock) {
        return merchantService.editSingleSkuStock(skuId, stock);
    }

    @ApiOperation("修改价格")
    @PostMapping("/editSkuPrice")
    public BaseResp editSkuPrice(@RequestBody EditSkuPriceReq req) {
        return merchantService.editSkuPrice(req);
    }

    @ApiOperation("修改供货价")
    @PostMapping("/editChangePrice")
    public BaseResp editChangePrice(@RequestBody EditChangePriceReq req) {
        return merchantService.editChangePrice(req);
    }

    @ApiOperation("修改商品属性")
    @PostMapping("/editSpuField")
    public BaseResp editSpuField(@RequestBody SpuFiledReq req) {
        return merchantService.editSpuField(req);
    }

    @ApiOperation("获取店铺业绩排名分页")
    @PostMapping("/getShopAmountPage")
    public ResultData<BasePageResp<ShopAmountVO>> getShopAmountPage(@RequestBody ShopAmountReq req) {
        return merchantService.getShopAmountPage(req);
    }

    @ApiOperation("获取店铺销售额订单分页")
    @PostMapping("/getAmountOrderPage")
    public ResultData<BasePageResp<OrderResp>> getAmountOrderPage(@RequestBody OrderPageReq req) {
        return merchantService.getAmountOrderPage(req);
    }

    @ApiOperation("获取每月销售额列表")
    @PostMapping("/getMonthAmountOrderList")
    public ResultData<List<StatisticsVO>> getMonthAmountOrderList(@RequestBody OrderMonthStatisticsReq req) {
        return merchantService.getMonthAmountOrderList(req);
    }

    @ApiOperation("商户上下架商品")
    @GetMapping("/editProductHidden")
    public BaseResp editProductHidden(@RequestParam("id") Long id) {
        return merchantService.editProductHidden(id);
    }

    @ApiOperation("获取订单物流信息")
    @GetMapping("/getLogisticsTrace")
    public ResultData<String> getLogisticsTrace(@AuthenticationPrincipal User user, @RequestParam("orderId") Long orderId) {
        return merchantService.getLogisticsTrace(user, orderId);
    }

    @ApiOperation("获取一年中每月销售额统计")
    @GetMapping("/getOrderStatisticsByYear")
    public ResultData<OrderStatisticsVO> getOrderStatisticsByYear(@RequestParam("year") Integer year) {
        return merchantService.getOrderStatisticsByYear(year);
    }

    @ApiOperation("获取指定商品的统计数据")
    @PostMapping("/getSpuStatistics")
    public ResultData<SpuSellStatisticsVO> getSpuSellStatistics(@RequestBody SpuSellStatisticsReq req) {
        return merchantService.getSpuSellStatistics(req);
    }

    @ApiOperation("获取类目分页")
    @PostMapping("/getCategoryPage")
    public ResultData<BasePageResp<Category>> getCategoryPage(@RequestBody CategoryReq req) {
        return merchantService.getCategoryPage(req);
    }

    @ApiOperation("获取类目品牌、销售属性、自然属性")
    @GetMapping("/getCategoryInfo")
    public ResultData<CategoryInfoResp> getCategoryInfo(@RequestParam("id") Long id) {
        return merchantService.getCategoryInfo(id);
    }

    @ApiOperation("获取商家后台统计数据")
    @PostMapping("/getShopStatisticsData")
    public ResultData<ShopStatisticsDataVO> getShopStatisticsData(@RequestBody TimeRangeReq req) {
        return merchantService.getShopStatisticsData(req);
    }

    @ApiOperation("获取商品点击人数趋势")
    @PostMapping("/getSpuClickTrend")
    public ResultData<SpuTrendVO> getSpuClickTrend(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuClickTrend(req);
    }

    @ApiOperation("获取商品访客趋势")
    @PostMapping("/getSpuVisitorTrend")
    public ResultData<SpuTrendVO> getSpuVisitorTrend(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuVisitorTrend(req);
    }

    @ApiOperation("获取商品退款订单量趋势")
    @PostMapping("/getSpuRefundCountTrend")
    public ResultData<SpuTrendVO> getSpuRefundCountTrend(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuRefundCountTrend(req);
    }

    @ApiOperation("获取成交订单趋势")
    @PostMapping("/getSpuCompleteTrend")
    public ResultData<SpuTrendVO> getSpuCompleteTrend(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuCompleteTrend(req);
    }

    @ApiOperation("获取成交人数趋势")
    @PostMapping("/getSpuCustomerTrend")
    public ResultData<SpuTrendVO> getSpuCustomerTrend(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuCustomerTrend(req);
    }

    @ApiOperation("获取商品数据")
    @PostMapping("/getSpuRateData")
    public ResultData<ShopStatisticsDataVO> getSpuRateData(@RequestBody TimeRangeReq req) {
        return merchantService.getSpuRateData(req);
    }

    @ApiOperation("获取时间段内商品数据")
    @PostMapping("/getSpuSellDataPage")
    public ResultData<BasePageResp<SpuSellDataVO>> getSpuSellDataPage(@RequestBody SpuSellDataReq req) {
        return merchantService.getSpuSellDataPage(req);
    }

    @ApiOperation("修改订单备注")
    @PostMapping("/editOrderRemark")
    public BaseResp editOrderRemark(@RequestBody Orders orders) {
        return merchantService.editOrderRemark(orders);
    }

    @ApiOperation("修改店铺简介")
    @PostMapping("/editShopIntroduction")
    public BaseResp editShopIntroduction(@RequestBody CompanyIntroduction req) {
        return merchantService.editShopIntroduction(req);
    }

    @ApiOperation("修改平台自动回复模版")
    @GetMapping("/editAutoReplyFormat")
    public BaseResp editAutoReplyFormat(@RequestParam("replyFormat") String replyFormat) {
        return merchantService.editAutoReplyFormat(replyFormat);
    }

}
